package com.itheima.demo;

import com.itheima.domain.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

public class DemoTest {
    public static void main(String[] args) throws Exception {
        method1();
    }

    public static void method1()throws Exception {
        //查询所有
        //1.读取核心配置文件
        InputStream is = Resources.getResourceAsStream("sql.xml");
        //2、构建SqlSessionFactory对象
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(is);
        //3.获取SqlSession对象
        SqlSession session = factory.openSession();
        //4、调用statement对象并执行:namespace+"."+statement对象的id
        List<User> list = session.selectList("one.findAll");
        System.out.println("list = " + list);
        //事务提交
        session.commit();
        //释放资源
        session.commit();
        is.close();
    }
}
